<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="场站名称" prop="beginChargeTime">
        <el-input
          v-model="queryParams.parkinglockStationName"
          placeholder="请输入场站名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="关联订单ID" prop="chargeOrderId">
        <el-input
          v-model="queryParams.chargeOrderId"
          placeholder="请输入关联订单ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开启计费" prop="enableFee">
        <el-input
          v-model="queryParams.enableFee"
          placeholder="请输入开启计费"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结束充电时间" prop="endChargeTime">
        <el-input
          v-model="queryParams.endChargeTime"
          placeholder="请输入结束充电时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最后更新时间" prop="lastUpdateTime">
        <el-input
          v-model="queryParams.lastUpdateTime"
          placeholder="请输入最后更新时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="降锁时间" prop="lockDownTime">
        <el-input
          v-model="queryParams.lockDownTime"
          placeholder="请输入降锁时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="升锁时间" prop="lockUpTime">
        <el-input
          v-model="queryParams.lockUpTime"
          placeholder="请输入升锁时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车位ID" prop="parkId">
        <el-input
          v-model="queryParams.parkId"
          placeholder="请输入车位ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车位锁ID" prop="parkinglockId">
        <el-input
          v-model="queryParams.parkinglockId"
          placeholder="请输入车位锁ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车位锁场站ID" prop="parkinglockStationId">
        <el-input
          v-model="queryParams.parkinglockStationId"
          placeholder="请输入车位锁场站ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付ID" prop="payId">
        <el-input
          v-model="queryParams.payId"
          placeholder="请输入支付ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付占位费" prop="payTotalForParking">
        <el-input
          v-model="queryParams.payTotalForParking"
          placeholder="请输入支付占位费"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预支付金额" prop="planPayTotal">
        <el-input
          v-model="queryParams.planPayTotal"
          placeholder="请输入预支付金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:parkingOrder:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:parkingOrder:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:parkingOrder:remove']"
        >删除
        </el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:parkingOrder:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="parkingOrderList" @selection-change="handleSelectionChange">
      <el-table-column label="占位订单编号" align="center" prop="id"/>
      <el-table-column label="场站名称" align="center" prop="parkinglockStationName" width="240"/>
      <el-table-column label="占位锁ID" align="center" prop="parkId"/>
      <el-table-column label="占位锁序号" align="center" prop="parkName"/>
      <el-table-column label="订单状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag :type="statusTypeList[scope.row.status].type" effect="dark">{{ statusTypeList[scope.row.status].label }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="占位时长" align="center" prop="parkIngTime"/>
      <el-table-column label="预支付金额(元)" align="center" prop="planPayTotalShow"/>
      <el-table-column label="应收金额(元)" align="center" prop="realTotalForParkingShow"/>
      <el-table-column label="实收金额(元)" align="center" prop="payTotalForParkingShow"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:parkingOrder:edit']"
          >订单详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改车位锁订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" fullscreen append-to-body :show-close="false">
      <el-descriptions class="margin-top" title="占位订单信息&用户信息" :column="5" border :labelStyle="labelClassName" :contentStyle="contentStyle">
        <template slot="extra">
          <el-button type="primary" @click="resetUp">刷 新</el-button>
          <el-button @click="cancel">关闭</el-button>
        </template>
        <el-descriptions-item>
          <template slot="label">
            占位订单编号
          </template>
          {{parkinglockOrder.id}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            订单状态
          </template>
            <el-tag size="mini" v-if="parkinglockOrder.status" :type="statusTypeList[parkinglockOrder.status].type" effect="dark">{{ statusTypeList[parkinglockOrder.status].label }}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            充电场站名称
          </template>
          {{parkinglockOrder.parkinglockStationName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            占位锁ID
          </template>
          {{parkinglockOrder.parkId}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            占位锁序号
          </template>
          {{parkinglockOrder.parkName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            用户名称
          </template>
          {{consumer.nickName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            注册手机号
          </template>
          {{consumer.phoneNum}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            首充场站
          </template>
          {{consumer.firstStationName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            是否管理员
          </template>
          {{consumer.isManager ? '是' : '否'}}
        </el-descriptions-item>
      </el-descriptions>
      <el-descriptions v-if="wxPayOrder" class="margin-top" title="计费规则&支付信息" :column="5" border :labelStyle="labelClassName" :contentStyle="contentStyle">
        <el-descriptions-item>
          <template slot="label">
            计费规则ID
          </template>
          {{parkinglockPrice.id}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            计费周期(分钟)
          </template>
          {{parkinglockPrice.cycleOfMinute}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            免费时长(分钟)
          </template>
          {{parkinglockPrice.freeTime}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            周期费用(元)
          </template>
          {{parkinglockPrice.cycleFeeShow}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            最高收费(元)
          </template>
          {{parkinglockPrice.maxFeeShow}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            支付金额(元)
          </template>
          {{wxPayOrder.payMoneyTotalShow}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            支付状态
          </template>
          <el-tag size="mini" v-if="wxPayOrder.status" :type="statusOrderTypeList[wxPayOrder.status].type" effect="dark">{{ statusOrderTypeList[wxPayOrder.status].label }}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            退款金额(元)
          </template>
          {{wxPayOrder.refundMoneyShow}}
        </el-descriptions-item>
        <el-descriptions-item >
          <template slot="label">
            支付订单号
          </template>
          {{wxPayOrder.wxPayId}}
        </el-descriptions-item>
      </el-descriptions>
      <el-descriptions v-if="chargeOrder" style="width: 746px;" title="充电订单信息" class="margin-top" :column="2" border :labelStyle="labelClassName" :contentStyle="contentStyle">
        <el-descriptions-item>
          <template slot="label">
            充电订单编号
          </template>
          {{chargeOrder.id}}
        </el-descriptions-item>
        <el-descriptions-item v-if="chargeOrder.status">
          <template slot="label">
            充电状态
          </template>
          <el-tag size="mini" style="border: none" :color="statusTypeBg[chargeOrder.status]" effect="dark" type="">{{ statusChageTypeList[chargeOrder.status].label }}</el-tag>
        </el-descriptions-item>
      </el-descriptions>
      <el-descriptions title="占位计费" style="width: 1115px;" class="margin-top" :column="3" border :labelStyle="labelClassName" :contentStyle="contentStyle">
        <el-descriptions-item>
          <template slot="label">
            占位时长
          </template>
          {{parkinglockOrder.parkIngTime}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            应收金额(元)
          </template>
          {{parkinglockOrder.parkIngFee}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            实收金额(元)
          </template>
          {{parkinglockOrder.realTotalForParkingShow}}
        </el-descriptions-item>
      </el-descriptions>
      <div style="height: 300px; margin-top: 20px;">
        <el-steps direction="vertical" :active="setpList.length">
          <template v-for="(item, index) in setpList">
            <el-step v-if="item && item !== undefined && item !== null && Object.keys(item).length > 0">
              <div slot="description">
                <el-table
                  border
                  v-loading=""
                  :data="[item]"
                  :style="{width: (index == setpList.length - 1 ?'90%':'100%')}">
                  <el-table-column
                    :label="item.stageStart + '→' + item.stageEnd"
                  >
                    <template slot-scope="scope">
                      {{item.stageStartTime}} 至 {{item.stageEndTime}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="占位时长"
                  >
                    <template slot-scope="scope">
                      {{item.time}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="应收金额(元)"
                  >
                    <template slot-scope="scope">
                      {{item.charge}}
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-step>
          </template>
        </el-steps>
      </div>
      <!--<div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="resetUp">刷 新</el-button>
        <el-button @click="cancel">关闭</el-button>
      </div>-->
    </el-dialog>
  </div>
</template>

<script>
import {
  listParkingOrder,
  getParkingOrder,
  delParkingOrder,
  addParkingOrder,
  updateParkingOrder
} from "@/api/business/parkingOrder";
const statusTypeList = [
  {
    value: 0,
    label: '初始值',
    type: 'info'
  },
  {
    value: 1,
    label: '降锁成功',
    type: ''
  },
  {
    value: 2,
    label: '降锁失败',
    type: 'danger'
  },
  {
    value: 3,
    label: '已升锁',
    type: 'success'
  }
]
const statusOrderTypeList = [
  {
    value: 0,
    label: '创建',
    type: 'info'
  },
  {
    value: 1,
    label: '支付成功',
    type: 'success'
  },
  {
    value: 2,
    label: '未支付',
    type: 'warning'
  },
  {
    value: 3,
    label: '已关闭',
    type: 'primary'
  },
  {
    value: 4,
    label: '转入退款',
    type: 'danger'
  },
  {
    value: 5,
    label: '退款成功',
    type: 'danger'
  },
  {
    value: 6,
    label: '退款关闭',
    type: 'danger'
  },
  {
    value: 7,
    label: '退款异常',
    type: 'danger'
  },
  {
    value: 8,
    label: '退款处理中',
    type: 'success'
  }
]
const statusTypeBg = {
  0: '#66CCCC',
  1: '#CCFF66',
  2: '#FF99CC',
  3: '#99CC33',
  4: '#FF9900',
  5: '#FFCC00',
  6: '#993366',
  7: '#FF0033'
}
const statusChageTypeList = [
  {
    value: 0,
    label: '创建预订单'
  },
  {
    value: 1,
    label: '加入开电队列'
  },
  {
    value: 2,
    label: '发出开电指令'
  },
  {
    value: 3,
    label: '开电成功'
  },
  {
    value: 4,
    label: '停止充电'
  },
  {
    value: 5,
    label: '结算订单'
  },
  {
    value: 6,
    label: '订单关闭'
  },
  {
    value: 7,
    label: '支付失败'
  },
]
export default {
  name: "ParkingOrder",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车位锁订单表格数据
      parkingOrderList: [],
      // 弹出层标题
      title: "订单详情",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        beginChargeTime: null,
        chargeOrderId: null,
        enableFee: null,
        endChargeTime: null,
        lastUpdateTime: null,
        lockDownTime: null,
        lockDownType: null,
        lockUpTime: null,
        lockUpType: null,
        parkId: null,
        parkinglockId: null,
        parkinglockStationId: null,
        payId: null,
        payTotalForParking: null,
        planPayTotal: null,
        parkinglockStationName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      detail: {},
      labelClassName: {
        width: '150px',
       /* backgroundColor: '#1890ff',
        color: '#ffffff',
        border: '1px solid #003366',*/
        fontWeight: 'bold'
      },
      contentStyle: {
        width: '150px',
        /*backgroundColor: '#F1F1F1',
        border: '1px solid #003366'*/
      },
      statusTypeList,
      statusOrderTypeList,
      statusChageTypeList,
      statusTypeBg,
      parkinglockOrder: {},
      consumer: {},
      parkinglockPrice: {},
      wxPayOrder: {},
      chargeOrder: {},
      parkIngOrderBeginVo: [],
      parkIngOrderIngVo: [],
      parkIngOrderEndVo: [],
      setpList: [],
      checkId: ''
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询车位锁订单列表 */
    getList() {
      this.loading = true;
      listParkingOrder(this.queryParams).then(response => {
        this.parkingOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        beginChargeTime: null,
        chargeOrderId: null,
        createTime: null,
        enableFee: null,
        endChargeTime: null,
        lastUpdateTime: null,
        lockDownTime: null,
        lockDownType: null,
        lockUpTime: null,
        lockUpType: null,
        parkId: null,
        parkinglockId: null,
        parkinglockStationId: null,
        payId: null,
        payTotalForParking: null,
        planPayTotal: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加车位锁订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids
      this.checkId = row.id || this.ids
      getParkingOrder(this.checkId).then(response => {
        this.detail = response.data;
        this.parkinglockOrder = response.data.parkinglockOrder
        this.consumer = response.data.consumer
        this.parkinglockPrice = response.data.parkinglockPrice
        this.wxPayOrder = response.data.wxPayOrder
        this.chargeOrder = response.data.chargeOrder
        this.parkIngOrderBeginVo = response.data.parkIngOrderBeginVo
        this.parkIngOrderIngVo = response.data.parkIngOrderIngVo
        this.parkIngOrderEndVo = response.data.parkIngOrderEndVo
        this.setpList = [
          this.parkIngOrderBeginVo,
          this.parkIngOrderIngVo,
          this.parkIngOrderEndVo
        ]
        this.open = true;
        this.title = "订单详情";
      });
    },
    resetUp() {
      getParkingOrder(this.checkId).then(response => {
        this.detail = response.data;
        this.parkinglockOrder = response.data.parkinglockOrder
        this.consumer = response.data.consumer
        this.parkinglockPrice = response.data.parkinglockPrice
        this.wxPayOrder = response.data.wxPayOrder
        this.chargeOrder = response.data.chargeOrder
        this.parkIngOrderBeginVo = response.data.parkIngOrderBeginVo
        this.parkIngOrderIngVo = response.data.parkIngOrderIngVo
        this.parkIngOrderEndVo = response.data.parkIngOrderEndVo
        this.setpList = [
          this.parkIngOrderBeginVo,
          this.parkIngOrderIngVo,
          this.parkIngOrderEndVo
        ]
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateParkingOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addParkingOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除车位锁订单编号为"' + ids + '"的数据项？').then(function () {
        return delParkingOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/parkingOrder/export', {
        ...this.queryParams
      }, `parkingOrder_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
  .margin-top{
    margin-bottom: 20px;
  }
  /deep/ .el-dialog__body{
    padding-top: 10px !important;
  }
</style>
